package com.quanyan.stadium.utils;

import java.text.DecimalFormat;
import java.util.*;

/**
 * Created by xiaoxiao on 16/5/27.
 */
public class GameCategoryScoreUtils {


    //K值说明,如：培训、约球、队内训练、PK的K值均为1，周、月、季度、年度城市、年度全国赛的K值分别为5、10、20、50、100.
    public static final int GAME_CATEGORY_SCORE_DEFAULT_K = 1;
    public static final int GAME_CATEGORY_SCORE_WEEK_K = 5;
    public static final int GAME_CATEGORY_SCORE_MONTH_K = 10;
    public static final int GAME_CATEGORY_SCORE_QUARTER_K = 20;
    public static final int GAME_CATEGORY_SCORE_YEAR_K = 50;
    public static final int GAME_CATEGORY_SCORE_YEAR_COUNTRY_K = 100;


    //Tn为时间指数，培训、约球、队内训练Tn为活动小时数，PK赛及其他系列赛，Tn=1;
    public static final int GAME_CATEGORY_SCORE_DEFAULT_TN = 1;

    //Z为某选手所取得的个人名次
    //M为奖牌增值，Z=1，M=4；Z=2，M=2；Z=3，M=1，Z为其他值时，M=0
    // N为总人数，



    /**
     * 计算当前比赛/活动用户的积分
     *
     * */
    public static Double getUserCategoryScore(Integer K, Integer Tn, int N, int Z, Date startTime){
        Calendar cal = Calendar.getInstance();
        cal.setTime(startTime);
        int month = cal.get(Calendar.MONTH) + 1;
        int dayOfMonth = cal.get(Calendar.DAY_OF_MONTH);
        double smallScore = 0.01/(month+dayOfMonth);
        DecimalFormat df = new DecimalFormat("#.00000");
        if (null == K) {
            K = 1;
        }
        if (null == Tn) {
            Tn = 1;
        }
        return Double.valueOf(df.format(K * Tn * (1 + (N - Z + getM(N))) + smallScore));
    }

    /**
     * 根据赛事级别获取赛事的K值
     *
     * 默认0，0、积分赛；1、月度馆内赛；2、季度分区赛；3、年度城市赛；4、年度全国赛; 5、周赛
     *
     * */
    public static int getOfficialGameEventK(Byte type){
        int K;
        if (type.intValue() == 1) {
            K = 10;
        }else if (type.intValue() == 2) {
            K = 20;
        }else if (type.intValue() == 3) {
            K = 50;
        }else if (type.intValue() == 4){
            K = 100;
        }else if (type.intValue() == 5){
            K = 5;
        }else {
            K = 1;
        }
        return K;
    }

    private static int getM(int Z) {
        int M;
        if (Z == 1) {
            M = 4;
        }else if (Z == 2) {
            M = 2;
        }else if (Z == 3) {
            M = 1;
        }else {
            M = 0;
        }
        return M;
    }


    public static void main(String[] args){


        System.out.println(GameCategoryScoreUtils.getUserCategoryScore(1, 1, 10, 1, new Date()));
        System.out.println(GameCategoryScoreUtils.getUserCategoryScore(1, 1, 10, 2, new Date()));
        System.out.println(GameCategoryScoreUtils.getUserCategoryScore(1, 1, 10, 3, new Date()));
        System.out.println(GameCategoryScoreUtils.getUserCategoryScore(1, 1, 10, 4, new Date()));


        List<Integer> uids = new ArrayList<>();
        uids.add(1);
        uids.add(2);
        uids.add(2);
        uids.add(3);

        System.out.println(uids.size());
        HashSet<Integer> tempSet = new HashSet<>(uids);
        uids = new ArrayList<>(tempSet);
        System.out.println(uids.size());

    }


}
